package com.amigo.online.provider.merchant.config;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

/**
 * @version: V 1.0.0
 * @Description: （线程池配置中心）
 * @author: zxy  QQ:1363320658
 * @date: 2018年12月10日 下午3:05:08
 */
@Configuration
public class ExecutorConfig {

    /**
     * @throws
     * @Title: buildConsumerQueueThreadPool
     * @Description: ()
     * @param: @return
     * @return: ExecutorService
     */
    @Bean(value = "queueThreadPool")
    public ExecutorService buildConsumerQueueThreadPool() {
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
                .setNameFormat("consumer-queue-thread-%d").build();
        ExecutorService pool = new ThreadPoolExecutor(16, 64, 0L, TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<Runnable>(5), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());

        return pool;
    }

}